// manager/pages/editperson/index.js
import config from '../../../utils/config';
import { request, uploadFile } from '../../../utils/request';
import util from '../../../common/util';
import WxValidate from '../../../common/WxValidate';
import validateIdent from '../../../common/validateIdent';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        baseUrl: config.baseUrl,
        activeIndex: 1,
        stepList: [
            {
                id: 1,
                text: "添加个人"
            },
            {
                id: 2,
                text: "首次拜访"
            }
        ],
        showCourse: false,
        // 网格列表
        showArea: false,
        params: {
            areaName: ""
        },
        scroller: {
			pageNum: 0,
			pageSize: 10,
			totalPage: 10,
			isNoneLoading: true,
			refreshColor: '#000000',
			refreshDiy: false,
			isloaded: false,
			list: []
        },
        currentArea: null,
        /* 添加个人 */
        // 字典
        dict: {},
        latitude: "",
        longitude: "",
        personForm: {
            perType: "",
            perAreaId: "",
            areaName: "",
            perCustName: "",
            perCustPhone: "",
            perCustIdcard: "",
            perIdcardHead: "",
            perIdcardBadge: "",
            perIsHouseholder: "",
            perMaritalStatus: "",
            perResidentialStatus: "",
            perResidentialAddress: "",
            ecardApiMerchantPartInfos: [],
            ecardApiPersonManageWork: {
                manageBusinessProject: "",
                workUnit: "",
                manageSituation: "",
                manageCoordinate: "",
                manageMapAddress: "",
                manageBusinessPic: "",
                manageLicenseName: "",
                manageLicensePic: "",
            },
            perBusinessLabel: "",
            perMarketingFocus: "",
            perLabel: "",
            perLevel: "",
            remark: "",
        },
        keynoteList: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        if(options.personId){
            this.setData({
                ['personForm.id']: options.personId,
            })
            wx.setNavigationBarTitle({
                title: "编辑个人"
            })
            this.getPersonInfo();
        }else{
            // 获取当前位置
            this.getLatLng();
        }

        this.initPersonTopValidate();
        this.initPersonNongHuBotValidate();
        this.initPersonXinShiMinBotValidate();
        this.initContactValidate();
        
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },
    /**
     * 关闭提示
     */
    closeCourse(){
        
    },

    /**
     * 输入框输入时
     */
    input(e){
        let key = e.target.dataset.key;
        this.setData({
            ['personForm.'+key]: e.detail.value
        })  
    },

    /**
     * 选择框变化时
     */
    pickerChagne(e){
        let { key, value } = e.detail;
        this.setData({
            ['personForm.'+key]: value
        })
    },

    /**
     * 日期选择
     */
    bindDateChange: function(e) {
        let { key } = e.currentTarget.dataset;
        this.setData({
            ['personForm.'+key]: e.detail.value
        }) 
    },

    // 个人信息
    getPersonInfo(){
        request({
            url: "/personMarketing/getPersonInfo",
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {
                id: this.data.personForm.id
            }
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    personForm: {...res.data}
                })
                if(!res.data.ecardApiMerchantPartInfos || res.data.ecardApiMerchantPartInfos.length == 0){
                    // 联系人初始化
                    this.addContact();
                }
                this.getDictionaryInfo('ecard_person_type');
                this.getDictionaryInfo('common_yes_no');
                this.getDictionaryInfo('ecard_person_marital');
                this.getDictionaryInfo('ecard_person_residential');
                this.getDictionaryInfo('ecard_agriculture_relationship');
                this.getDictionaryInfo('ecard_person_business_project');
                this.getDictionaryInfo('ecard_person_business_tag');
                this.getDictionaryInfo('ecard_person_tag');
                this.getDictionaryInfo('ecard_person_level');
            }
        }).catch(error => {
            // console.log(error)
        })
    },


    /**
     * 显示网格
     */
    showAreaPopup(){
        this.setData({
            showArea: true,
        })
        this.refresh();
    },
    
    /** 关闭网格 */
    closeArea(){
        this.setData({
            showArea: false
        })
    },
    /**
     * 输入框输入时
     */
    paramsInput(e){
        let key = e.target.dataset.key;
        this.setData({
            ['params.'+key]: e.detail.value,
            // isFilter: !!e.detail.value,
        })
    },
    // 搜索
    searchConfirm(e){
        console.log(e.detail.value)
        this.setData({
            'params.locationName': e.detail.value
        })
        // 页面加载时执行一次加载
		this.resetScroller()
        this.getPersonAreaInfoList();
    },
    searchBtn(e){
        this.resetScroller()
        this.getPersonAreaInfoList();
    },
    /**
     * 重置下拉
     */
    resetScroller(){
        let scroller = {
			pageNum: 0,
			pageSize: 10,
			totalPage: 10,
			isNoneLoading: true,
			refreshColor: '#000000',
			refreshDiy: false,
			isloaded: false,
			list: []
		}
		this.setData({
            scroller,
		})
    },
    refresh: function () {
        this.resetScroller()
        this.getPersonAreaInfoList()
    },
    
	loadMore: function () {
        console.log("loadMore")
		this.getPersonAreaInfoList()
    },

    /**
     * 获取网格
     */
    getPersonAreaInfoList() {
		let { scroller } = this.data;
        scroller.pageNum = scroller.pageNum + 1;
        if(scroller.pageNum>scroller.totalPage){
            return
        }
        request({
            url: `/personMarketing/getPersonAreaInfoList`,
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {
                ...this.data.params,
                type: 1,
                pageNum: this.data.scroller.pageNum,
                pageSize: this.data.scroller.pageSize,
            }
        }).then(res => {
            if(res.code == 0){
                scroller.totalPage = Math.ceil(res.total/scroller.pageSize);
                if(scroller.pageNum>=scroller.totalPage){
                    scroller.isNoneLoading = false;
                }
                if(res.data.length>0){
                    res.data.map(item => {
                        item.creationTime = util.formatTime(new Date(item.creationTime));
                        // item.lastVisitDate = item.lastVisitDate?util.formatTime(new Date(item.lastVisitDate)):"";
                        return item
                    })
                }
                if(scroller.pageNum == 1){
                    scroller.list = res.data;
                }else{
                    scroller.list = scroller.list.concat(res.data);
                }
                this.setData({
                    scroller
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },

    /** 新建网格 */
    toAddarea(){
        wx.navigateTo({
          url: '/manager/pages/addarea/index',
        })
    },

    /** 选择网格 */
    buildChange(e){
        console.log(e)
        let { item } = e.currentTarget.dataset;
        this.setData({
            currentArea: item
        })
    },

    /** 确认网格 */
    confirmArea(){
        if(!this.data.currentArea){
            wx.showToast({
                title: '请选择网格',
                icon: 'none',
                duration: 2000
            })
            return
        }
        let { personForm } = this.data;
        request({
            url: "/personMarketing/computePerAndAreaRadius",
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: false, // 返回值是否解密
            data: {
                coordinate: personForm.ecardApiPersonManageWork.manageCoordinate,
                id: this.data.currentArea.id
            },
        }).then(res => {
            if(res.code == 0){
                personForm.perAreaId = this.data.currentArea.id;
                personForm.areaName = this.data.currentArea.areaName;
                this.setData({
                    showArea: false,
                    personForm
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },

    /** 上传身份证 */
    uploadID(e){
        let that = this;
        let { device, path } = e.detail;
        wx.compressImage({
            src: path, // 图片路径
            quality: 40, // 压缩质量
            success(res1) {
                uploadFile({
                    url: "/commonApi/imageUpload",
                    filePath: res1.tempFilePath,
                    name: "imgfile",
                    formData: {
                        fileName: device
                    }
                }).then(res => {
                    if(res.code == 0){
                        if(device == "idCardFront"){
                            that.setData({
                                'personForm.perIdcardHead': res.data
                            })
                        }
                        if(device == "idCardBack"){
                            that.setData({
                                'personForm.perIdcardBadge': res.data
                            })
                        }
                    }
                }).catch(error => {
                    // console.log(error)
                })
            }
        })        
    },

    /** 联系人输入框输入时 */
    contactInput(e){
        let { key, index} = e.target.dataset;
        let { personForm } = this.data;
        let item = personForm.ecardApiMerchantPartInfos[index];
        item[key] = e.detail.value;
        personForm.ecardApiMerchantPartInfos.splice(index,1,item);
        this.setData({
            personForm
        })
    },

    /** 联系人选择框变化时 */
    contactPickerChagne(e){
        let { index} = e.target.dataset;
        let { key, value } = e.detail;
        let { personForm } = this.data;
        let item = personForm.ecardApiMerchantPartInfos[index];
        item[key] = value;
        personForm.ecardApiMerchantPartInfos.splice(index,1,item);
        this.setData({
            personForm
        })
    },
    /** 经营情况输入框输入时 */
    personWorkInput(e){
        let { key } = e.target.dataset;
        let { personForm } = this.data;
        personForm.ecardApiPersonManageWork[key] = e.detail.value;
        this.setData({
            personForm
        })
    },

    /** 经营情况选择框变化时 */
    pickerPersonWorkChagne(e){
        let { key, value } = e.detail;
        let { personForm } = this.data;
        personForm.ecardApiPersonManageWork[key] = value;
        this.setData({
            personForm
        })
    },

    /** 添加联系人 */
    addContact(){
        let { personForm } = this.data;
        personForm.ecardApiMerchantPartInfos.push({
            // id: util.getUuid(),
            name: "",
            relationship: "", 
            phone: "",
            idCard: "",
            learnWorkSituation: "",
        })
        this.setData({
            personForm
        })
    },
    /** 删除联系人 */
    deleteContact(e){
        console.log(e.currentTarget.dataset)
        let { index } = e.currentTarget.dataset;
        let { personForm } = this.data;
        personForm.ecardApiMerchantPartInfos.splice(index,1);
        this.setData({
            personForm
        })
    },

    /**
     * 企业标签
     */
    beTagChange(e) {
        let { key, item } =  e.currentTarget.dataset;
        let arr = this.data.personForm[key]?this.data.personForm[key].split(","):[];
        let index = arr.indexOf(item.dictValue);
        console.log(arr,arr.indexOf(item.dictValue))
        if(index == -1){
            arr.push(item.dictValue);
        }else{
            arr.splice(index,1);
        }
        this.setData({
            ['personForm.'+key]: arr.join(",")
        })
    },

    /**
     * 已开通业务、营销重点选择
     */
    onPersonCheckboxChange(e) {
        console.log(e)
        let { key, item } = e.currentTarget.dataset;
        let arr = this.data.personForm[key]?this.data.personForm[key].split(","):[];
        let index = arr.indexOf(item.dictValue);
        if(index != -1){
            arr.splice(index,1);
        }else{
            arr.push(item.dictValue);
        }
        this.setData({
            ['personForm.'+key]: arr.join(",")
        });
        if(key == "perBusinessLabel"){
            this.getKeynoteList(this.data.dict.ecard_person_business_tag);
        }
    },

    // 查看图片
    previewImage(e) {
        let { url } = e.currentTarget.dataset;
        wx.previewImage({
            current: url, // 当前显示图片的http链接
            urls: [url] // 需要预览的图片http链接列表
        })
    },

    /**
     * 获取字典
     */
    getDictionaryInfo(dictType) {
        request({
            url: "/commonApi/getDictionaryInfo",
            method: "GET",
            data: {
                dictType
            }
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    ['dict.'+dictType]: res.data
                })
                if(dictType == 'ecard_person_business_tag'){
                    this.getKeynoteList(res.data);
                }
            }
        }).catch(error => {
            // console.log(error)
        })
    },

    // 获取营销重点
    getKeynoteList(list){
        let keynoteList = [];
        let arr = this.data.personForm.perBusinessLabel?this.data.personForm.perBusinessLabel.split(","):[];
        let farr = this.data.personForm.perMarketingFocus?this.data.personForm.perMarketingFocus.split(","):[];
        console.log(this.data.personForm.perBusinessLabel)
        list.forEach(item => {
            console.log((arr.indexOf(item.dictValue)==-1))
            console.log(arr,item.dictValue)
            if(arr.indexOf(item.dictValue)==-1){
                keynoteList.push(item)
            }
        })
        arr.forEach(item => {
            let index = farr.indexOf(item);
            if(index != -1){
                farr.splice(index,1);
            }
        })
        console.log(farr)
        this.setData({
            keynoteList,
            ['personForm.perMarketingFocus']: farr.join(",")
        })
    },

    // 调整定位
    fineLocation(e){
        let that = this;
        wx.chooseLocation({
            latitude: this.data.latitude,
            longitude: this.data.longitude,
            scale: 18,
            success(res){
                console.log(res)
                let latitude = res.latitude;
                let longitude = res.longitude;
                request({
                    url: `/merchantMarketing/calculateDistance`,
                    reqRSAENCRY: true, // 参数是否加密
                    resRSADECRY: false, // 返回值是否解密
                    data: {
                        coordinate: `${that.data.latitude},${that.data.longitude}`,
                        chooseCoordinate: `${latitude},${longitude}`,
                    }
                }).then(res => {
                    if(res.code == 0){
                        that.setData({
                            latitude,
                            longitude
                        })
                        that.getCoordinatePositionInfo(latitude,longitude)
                    }
                }).catch(error => {
                    // console.log(error)
                })
            }
        })
    },
    
    // 获取经纬度
    getLatLng(){
        let that = this;
        wx.getSetting({
            success: (res) => {
                console.log(res)
                if (res.authSetting['scope.userLocation'] == false) {//非初始化进入该页面,且未授权
                    wx.showModal({
                        title: '是否授权当前位置',
                        content: '需要获取您的地理位置，请确认授权',
                        success: function (res) {
                            if (res.confirm) {
                                wx.openSetting({
                                    success: function (data) {
                                        // console.log(data);
                                        if (data.authSetting["scope.userLocation"] == true) {
                                            that.getLocation();
                                        }
                                    }
                                })
                            }
                        }
                    })
                } else {//初始化进入
                    // console.log("KKKKK") 
                    that.getLocation();
                }
            }
        })
    },
    getLocation(){
        const that = this;
        wx.getLocation({
            type: 'gcj02',
            altitude: true,
            isHighAccuracy: true,
            success (res) {
                that.setData({
                    latitude: res.latitude,
                    longitude: res.longitude,
                })
                that.getCoordinatePositionInfo(res.latitude,res.longitude)
            },
            complete: function(res) {
                console.log(res)
                if(res.errMsg == "getLocation:fail auth deny"){
                    // wx.showToast({
                    //     title: '获取定位失败',
                    //     icon: 'none',
                    //     duration: 2000
                    // });
                }
            }
        })
    },
    getCoordinatePositionInfo(latitude,longitude){
        // const that = this;
        let { personForm, visitForm } = this.data;
        request({
            url: "/commonApi/getCoordinatePositionInfo",
            method: "GET",
            data: {
                coordinate: `${latitude},${longitude}`
            }
        }).then(res => {
            if(res.code == 0){
                personForm.ecardApiPersonManageWork.manageCoordinate = `${latitude},${longitude}`;
                personForm.ecardApiPersonManageWork.manageMapAddress = res.data.address;
                personForm.perResidentialAddress = res.data.address;
                visitForm.coordinate = `${latitude},${longitude}`;
                visitForm.mapAddress = res.data.address;
                this.setData({
                    personForm,
                    visitForm
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },
    // 企业图片或营业执照图片上传
    uploadImage(e) { // 拍摄或从相册选取上传
        let { key, url } = e.detail;
        uploadFile({
            url: "/commonApi/imageUploadAddWatermark",
            filePath: url,
            name: "imgfile",
            formData: {
                coordinate: this.data.personForm.ecardApiPersonManageWork.manageCoordinate,
                watermark: this.data.personForm.ecardApiPersonManageWork.manageMapAddress,
                fileName: key
            }
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    ['personForm.ecardApiPersonManageWork.'+key]: res.data
                })
            }
        }).catch(error => {
            // console.log(error)
        })
                   
    },
    // 保存企业
    savePerson(e) {
        let { personForm } = this.data; 
        // 传入表单数据，调用验证方法
        if (!this.personTopWxValidate.checkForm(personForm)) {
            const error = this.personTopWxValidate.errorList[0]
            this.showModal(error)
            return false
        }
        
        // 验证联系人
        for (let i = 0; i < personForm.ecardApiMerchantPartInfos.length; i++) {
            if (!this.contactWxValidate.checkForm(personForm.ecardApiMerchantPartInfos[i])) {
                const error = this.contactWxValidate.errorList[0]
                this.showModal(error)
                return false
            }
        }
        if(!personForm.perType || personForm.perType == 1){
            // 传入表单数据，调用验证方法
            if (!this.personNongHuBotWxValidate.checkForm(personForm.ecardApiPersonManageWork)) {
                const error = this.personNongHuBotWxValidate.errorList[0]
                this.showModal(error)
                return false
            }
        }
        if(!personForm.perType || personForm.perType == 2){
            // 传入表单数据，调用验证方法
            if (!this.personXinShiMinBotWxValidate.checkForm(personForm.ecardApiPersonManageWork)) {
                const error = this.personXinShiMinBotWxValidate.errorList[0]
                this.showModal(error)
                return false
            }
        }
        if(!personForm.perBusinessLabel){
            wx.showToast({
                title: '请选择已开通业务',
                icon: 'none',
                duration: 2000
            }); 
            return
        }
        request({
            url: `/personMarketing/addPersonInfo`,
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: false, // 返回值是否解密
            data: personForm
        }).then(res => {
            if(res.code == 0){
                wx.showToast({
                    title: '保存成功',
                    icon: 'none',
                    mask: true,
                    duration: 2000
                });
                setTimeout(()=>{
                    wx.navigateBack()
                },2000)
            }
        }).catch(error => {
            // console.log(error)
        })
    },
    // 表单验证
    initPersonTopValidate() {
        // 验证字段的规则
        const rules = {
            perType: {
                required: true
            },
            perAreaId: {
                required: true
            },
            perCustName: {
                required: true
            },
            perCustPhone: {
                required: true,
                tel: true
            },
            perCustIdcard: {
                cardNo: true,
                checkProvince: true,
                checkBirthday: true,
                checkParity: true,
            },
        }
        // 验证字段的提示信息，若不传则调用默认的信息
        const messages = {
            perType: {
                required: '请选择个人客户类型'
            },
            perAreaId: {
                required: '请选择网格区域'
            },
            perCustName: {
                required: '请输入客户姓名'
            },
            perCustPhone: {
                required: '请输入联系方式',
                tel: '请输入正确的联系方式'
            },
            agrCustIdcard: {
                
            },
            
        }
        // 创建实例对象
        this.personTopWxValidate = new WxValidate(rules, messages)
        // 自定义验证规则
        this.personTopWxValidate.addMethod('name', (value, param) => {
            var returnVal = true;
            if(/^[\u4e00-\u9fa5]{2,6}$/.test(value)){
                returnVal = true;
            }else{
                returnVal = false;
                return false
            }
            return this.personTopWxValidate.optional(value) || returnVal
        }, '客户名称为2-6个中文')
        // 自定义验证规则
        this.personTopWxValidate.addMethod('cardNo', (value, param) => {
            var returnVal = true;
            if(value){
                if(validateIdent.IdentityCode_isCardNo(value)){
                    returnVal = true;
                }else{
                    returnVal = false;
                    return false
                }
                return this.personTopWxValidate.optional(value) || returnVal
            }else{
                return returnVal
            }
        }, '请输入18位身份证号')
        this.personTopWxValidate.addMethod('checkProvince', (value, param) => {
            var returnVal = true;
            if(value){
                if(validateIdent.IdentityCode_checkProvince(value)){
                    returnVal = true;
                }else{
                    returnVal = false;
                    return false
                }
                return this.personTopWxValidate.optional(value) || returnVal
            }else{
                return returnVal
            }
        }, '身份证号省份不正确')
        this.personTopWxValidate.addMethod('checkBirthday', (value, param) => {
            var returnVal = true;
            if(value){
                if(validateIdent.IdentityCode_checkBirthday(value)){
                    returnVal = true;
                }else{
                    returnVal = false;
                    return false
                }
                return this.personTopWxValidate.optional(value) || returnVal
            }else{
                return returnVal
            }
        }, '身份证号出生日期不正确')
        this.personTopWxValidate.addMethod('checkParity', (value, param) => {
            var returnVal = true;
            if(value){
                if(validateIdent.IdentityCode_checkParity(value)){
                    returnVal = true;
                }else{
                    returnVal = false;
                    return false
                }
                return this.personTopWxValidate.optional(value) || returnVal
            }else{
                return returnVal
            }
        }, '身份证号检验位不正确')
    },
    // 表单验证
    initPersonNongHuBotValidate() {
        // 验证字段的规则
        const rules = {
            manageBusinessProject: {
                required: true
            },
            manageCoordinate: {
                required: true
            },
        }
        // 验证字段的提示信息，若不传则调用默认的信息
        const messages = {
            manageBusinessProject: {
                required: '请选择经营项目'
            },
            manageCoordinate: {
                required: '地图位置'
            },
        }
        // 创建实例对象
        this.personNongHuBotWxValidate = new WxValidate(rules, messages)
    },
    // 表单验证
    initPersonXinShiMinBotValidate() {
        // 验证字段的规则
        const rules = {
            manageCoordinate: {
                required: true
            },
        }
        // 验证字段的提示信息，若不传则调用默认的信息
        const messages = {
            manageCoordinate: {
                required: '地图位置'
            },
        }
        // 创建实例对象
        this.personXinShiMinBotWxValidate = new WxValidate(rules, messages)
    },
    // 表单验证
    initContactValidate() {
        // 验证字段的规则
        const rules = {
            name: {
                required: true,
                name: true
            },
            relationship: {
                required: true,
            },
            phone: {
                required: true,
                tel: true
            },
            idCard: {
                // required: true,
                cardNo: true,
                checkProvince: true,
                checkBirthday: true,
                checkParity: true,
            },
        }
        // 验证字段的提示信息，若不传则调用默认的信息
        const messages = {
            name: {
                required: '请输入姓名',
            },
            relationship: {
                required: '请选择关系'
            },
            phone: {
                required: '请输入联系方式',
                tel: '请输入正确的联系方式'
            },
            idCard: {
                // required: '请输入身份证号',
                // idcard: '请输入正确的身份证号'
            },
        }
        this.contactWxValidate = new WxValidate(rules, messages)
        // 自定义验证规则
        this.contactWxValidate.addMethod('name', (value, param) => {
            var returnVal = true;
            if(/^[\u4e00-\u9fa5]{2,6}$/.test(value)){
                returnVal = true;
            }else{
                returnVal = false;
                return false
            }
            return this.contactWxValidate.optional(value) || returnVal
        }, '客户名称为2-6个中文')
        // 自定义验证规则
        this.contactWxValidate.addMethod('cardNo', (value, param) => {
            var returnVal = true;
            if(value){
                if(validateIdent.IdentityCode_isCardNo(value)){
                    returnVal = true;
                }else{
                    returnVal = false;
                    return false
                }
                return this.contactWxValidate.optional(value) || returnVal
            }else{
                return returnVal
            }
        }, '请输入18位身份证号')
        this.contactWxValidate.addMethod('checkProvince', (value, param) => {
            var returnVal = true;
            if(value){
                if(validateIdent.IdentityCode_checkProvince(value)){
                    returnVal = true;
                }else{
                    returnVal = false;
                    return false
                }
                return this.contactWxValidate.optional(value) || returnVal
            }else{
                return returnVal
            }
        }, '身份证号省份不正确')
        this.contactWxValidate.addMethod('checkBirthday', (value, param) => {
            var returnVal = true;
            if(value){
                if(validateIdent.IdentityCode_checkBirthday(value)){
                    returnVal = true;
                }else{
                    returnVal = false;
                    return false
                }
                return this.contactWxValidate.optional(value) || returnVal
            }else{
                return returnVal
            }
        }, '身份证号出生日期不正确')
        this.contactWxValidate.addMethod('checkParity', (value, param) => {
            var returnVal = true;
            if(value){
                if(validateIdent.IdentityCode_checkParity(value)){
                    returnVal = true;
                }else{
                    returnVal = false;
                    return false
                }
                return this.contactWxValidate.optional(value) || returnVal
            }else{
                return returnVal
            }
        }, '身份证号检验位不正确')
    },
    showModal(error) {
        wx.showToast({
            title: error.msg,
            icon: 'none',
            duration: 2000
        })
    },
})